<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>分类页</title>
    <link rel="stylesheet" href="./css/style.css">
</head>

<body>
    <div class="fix-title">
        <div class="back">&lt;</div>
        <span>商品列表</span>
        <div class="text"><a href="search.html">搜索</a></div>
    </div>
    <div class="cate-list-fix">
        <ul>
            <!-- <li class="active"><a href="">分类1</a></li>
            <li><a href=""><a href="">分类2</a></li>
            <li><a href=""><a href="">分类3</a></li>
            <li><a href=""><a href="">分类4</a></li>
            <li><a href=""><a href="">分类5</a></li> -->
        </ul>
    </div>
    <div class="good-list">
        <ul>
            <!-- <li>
                <img src="http://yun.itheima.com/Upload/Images/20220627/62b924298e658.jpg" alt="">
                <h3>商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称</h3>
                <p>
                    <span>￥200.200</span>
                    <span>+</span>
                </p>
            </li>
            <li>
                <img src="http://yun.itheima.com/Upload/Images/20220627/62b924298e658.jpg" alt="">
                <h3>商品名称</h3>
                <p>
                    <span>￥200.200</span>
                    <span>+</span>
                </p>
            </li>
            <li>
                <img src="http://yun.itheima.com/Upload/Images/20220627/62b924298e658.jpg" alt="">
                <h3>商品名称</h3>
                <p>
                    <span>￥200.200</span>
                    <span>+</span>
                </p>
            </li>
            <li>
                <img src="http://yun.itheima.com/Upload/Images/20220627/62b924298e658.jpg" alt="">
                <h3>商品名称</h3>
                <p>
                    <span>￥200.200</span>
                    <span>+</span>
                </p>
            </li>
            <li>
                <img src="http://yun.itheima.com/Upload/Images/20220627/62b924298e658.jpg" alt="">
                <h3>商品名称</h3>
                <p>
                    <span>￥200.200</span>
                    <span>+</span>
                </p>
            </li>
            <li>
                <img src="http://yun.itheima.com/Upload/Images/20220627/62b924298e658.jpg" alt="">
                <h3>商品名称</h3>
                <p>
                    <span>￥200.200</span>
                    <span>+</span>
                </p>
            </li> -->
        </ul>
        <div class="empty">
            <span>空空如也...</span>
        </div>
        <p class="desc">数据正在加载中...</p>
        <p class="desc">我也是有底线的...</p>
    </div>

    <script src="./js/jquery.js"></script>
    <!-- <script>
        $.ajax({
            method: 'get',
            url: 'http://124.223.14.236:3001/api/goods/',
            data: {
                cate_id: localStorage.getItem('ID')
            },
            success(res) {
                // console.log(res);
                const Str = res.data.list.map(function (index, item) {
                    // console.log(index);
                    return `<li>
                                <img src="${index.img}" alt="">
                                <h3>${index.title}</h3>
                                <p>
                                    <span>￥200.200</span>
                                    <span>+</span>
                                </p>
                            </li>`
                }).join('')
                $('.good-list ul').html(Str)
            }
        })


        $.ajax({
            method: 'GET',
            url: 'http://124.223.14.236:3001/api/goods',
            success(res) {
                // console.log(res);
                res.data.list.map(function (index, item) {
                    // console.log(index);
                    const newLi = `
                    <li>
                        <img src="${index.img}" alt="">
                        <h3>${index.title}</h3>
                        <p>
                            <span>￥200.200</span>
                            <span>+</span>
                        </p>
                    </li>
                    `
                    // $('.good-list ul').append(newLi)
                })
            }
        })

        $.ajax({
            method: 'GET',
            url: 'http://124.223.14.236:3001/api/goods/cate',
            success(res) {
                res.data.map(function (index, item) {
                    const newLi = `<li><a href="list.html" id=${index.id}>${index.name}</a></li>`
                    // console.log(index);
                    // console.log(index.name);
                    // console.log(index.id);
                    $('.cate-list-fix ul').append(newLi)
                })
            }
        })

        $('.cate-list-fix ul').on('click', function (e) {
            e.preventDefault()
            if (e.target.tagName === 'A') {
                $.ajax({
                    method: 'get',
                    url: 'http://124.223.14.236:3001/api/goods/',
                    data: {
                        cate_id: e.target.id
                    },
                    success(res) {
                        // console.log(res);
                        const Str = res.data.list.map(function (index, item) {
                            // console.log(index);
                            return `<li>
                                <img src="${index.img}" alt="">
                                <h3>${index.title}</h3>
                                <p>
                                    <span>￥200.200</span>
                                    <span>+</span>
                                </p>
                            </li>`
                        }).join('')
                        $('.good-list ul').html(Str)
                    }
                })
            }
        })
    </script> -->

    <script>
        $.ajax({
            method: 'get',
            url: 'http://124.223.14.236:3001/api/goods/',
            data: {
                cate_id: localStorage.get('ID')
            },
            success(res) {
                const str = res.data.list.map(function (index, item) {
                    return `<li>
                                <img src="${index.img}" alt="">
                                <h3>${index.title}</h3>
                                <p>
                                    <span>￥200.200</span>
                                    <span>+</span>
                                </p>
                            </li>`
                }).join('')
                $('.good-list ul').html(str)
            }
        })

        $.ajax({
            method: 'GET',
            url: 'http://124.223.14.236:3001/api/goods/cate',
            success(res) {
                // console.log(res);
                res.data.map(function (index, item) {
                    const newLi = `<li><a href="list.html" id=${index.id}>${index.name}</a></li>`
                    $('.cate-list-fix ul').append(newLi)
                })
            }
        })

        $.ajax({
            method: 'get',
            url: 'http://124.223.14.236:3001/api/goods',
            success(res) {
                console.log(res);
                res.data.list.map(function (index, item) {
                    const newLi = `<li>
                    <img src="${index.img}" alt="">
                    <h3>${index.title}</h3>
                    <p>
                        <span>￥200.200</span>
                        <span>+</span>
                    </p>
                </li>`
                    $('.good-list ul').append(newLi)
                })
            }
        })

        $('.cate-list-fix ul').on('click', function (e) {
            e.preventDefault()
            if (e.target.tagName === 'A') {
                $.ajax({
                    method: 'get',
                    url: 'http://124.223.14.236:3001/api/goods/',
                    data: {
                        cate_id: e.target.id
                    },
                    success(res) {
                        const str = res.data.list.map(function (index, item) {
                            return `<li>
                                <img src="${index.img}" alt="">
                                <h3>${index.title}</h3>
                                <p>
                                    <span>￥200.200</span>
                                    <span>+</span>
                                </p>
                            </li>`
                        }).join('')
                        $('.good-list ul').html(str)
                    }
                })
            }
        })
    </script>
</body>

</html>